package com.bzxgc.sgwer.service.impl.dept;

import com.bzxgc.sgwer.common.util.PageData;
import com.bzxgc.sgwer.dao.dept.DeptMapper;
import com.bzxgc.sgwer.entity.dept.Dept;
import com.bzxgc.sgwer.service.dept.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public void addDept(Dept dept) {
        dept.setAddTime(new Date());
        dept.setStatus(1);
        deptMapper.addDept(dept);
    }

    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(new Date());
        deptMapper.updateDept(dept);
    }

    @Override
    public void updateDeptStatus(Long[] ids, Integer status) {
        deptMapper.updateDeptStatus(ids, status);
    }

    @Override
    public Dept getDeptById(Long id) {
        return deptMapper.getDeptById(id);
    }

    @Override
    public Dept getDeptByName(String name) {
        return deptMapper.getDeptByName(name);
    }

    @Override
    public List<Dept> getDeptList() {
        return deptMapper.getDeptList();
    }

    @Override
    public PageData<Dept> getDeptListByPage(Integer pageNum, Integer pageSize, String name) {
        List<Dept> deptList = deptMapper.getDeptListByPage(PageData.fromIndex(pageNum, pageSize), pageSize, name);
        Integer totalRecord = deptMapper.getDeptCount(name);
        PageData<Dept> pageData = new PageData<>(pageSize, pageNum, totalRecord, deptList);
        return pageData;
    }

    @Override
    public Integer getDeptCount(String name) {
        return deptMapper.getDeptCount(name);
    }

}
